package com.ruoyi.btlfbreed.mapper;

import java.util.List;

import com.ruoyi.btlfbreed.domain.MyTbChickensVO;
import com.ruoyi.btlfbreed.domain.TbChickens;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 肉鸡Mapper接口
 * 
 * @author codeman
 * @date 2024-05-05
 */
public interface TbChickensMapper 
{
    /**
     * 查询肉鸡
     * 
     * @param chickenId 肉鸡主键
     * @return 肉鸡
     */
    public TbChickens selectTbChickensByChickenId(Long chickenId);

    /**
     * 查询肉鸡列表
     * 
     * @param tbChickens 肉鸡
     * @return 肉鸡集合
     */
    public List<TbChickens> selectTbChickensList(TbChickens tbChickens);

    /**
     * 新增肉鸡
     * 
     * @param tbChickens 肉鸡
     * @return 结果
     */
    public int insertTbChickens(TbChickens tbChickens);

    /**
     * 修改肉鸡
     * 
     * @param tbChickens 肉鸡
     * @return 结果
     */
    public int updateTbChickens(TbChickens tbChickens);

    /**
     * 删除肉鸡
     * 
     * @param chickenId 肉鸡主键
     * @return 结果
     */
    public int deleteTbChickensByChickenId(Long chickenId);

    /**
     * 批量删除肉鸡
     * 
     * @param chickenIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteTbChickensByChickenIds(Long[] chickenIds);


    @Select("<script> SELECT A.*, A.chicken_id chickenId,B.chicken_no chickenNo,count(*) OVER(PARTITION by type ORDER BY  sdate,type ) count FROM (\n" +
        "select '孵化记录' as sjname,birth_date as sdate, chicken_id, 1 as type from tb_chickens\n" +
        "UNION all\n" +
        "select '成长记录' as sjname,growth_date as sdate, chicken_id , 2 as type from tb_chicken_growth_records\n" +
        "UNION all\n" +
        "select '用药记录' as sjname,administration_date as sdate, chicken_id, 3 as type  from tb_medicine_records\n" +
        "UNION all\n" +
        "select '疫苗记录' as sjname,vaccination_date as sdate, chicken_id, 4 as type  from tb_vaccination_records\n" +
        "UNION all\n" +
        "select '出栏记录' as sjname,out_date as sdate, chicken_id, 5 as type  from tb_chicken_out_registry\n " +
        "UNION all\n" +
        "select '死亡记录' as sjname,death_date as sdate, chicken_id, 6 as type  from tb_chicken_death_records " +
        " ) AS A \n" +
        "LEFT JOIN tb_chickens B ON A.chicken_id=B.chicken_id\n" +
        "WHERE A.chicken_id=#{chickenId}\n" +
        "ORDER BY sdate,type  </script>")
    public List<MyTbChickensVO> getChickenData(@Param("chickenId") String chickenId);



}
